package com.ofhb.webapp.client.base;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.ofhb.webapp.client.AdminManager;
import com.ofhb.webapp.client.forms.HallForm;
import com.ofhb.webapp.client.forms.UserForm;
import com.ofhb.webapp.client.ui.grid.GridView;
import com.ofhb.webapp.client.ui.navbar.NavigationBar;
import com.ofhb.webapp.client.ui.navbar.events.NavChangeEvent;
import com.ofhb.webapp.client.ui.navbar.events.NavChangeEventHandler;
import com.ofhb.webapp.client.utils.AppClientUtils;

public class AppFrame extends VerticalPanel {
	private VerticalPanel vpAddNew;
	private VerticalPanel vpManage;
	private NavigationBar navigationBar;
	private TabPanel tabPanel;
	private HorizontalPanel hpFooter;
	public AppFrame() {
		setStyleName("app-base-frame");
		setWidth("1000px");
		
		FlexTable ftHeader = new FlexTable();
		add(ftHeader);
		ftHeader.setSize("100%", "75px");
		
		navigationBar = gerNavBar();
		navigationBar.draw();
		navigationBar.setSelectedIndex(0);
		
		add(navigationBar);
		
		add(AppClientUtils.getHorizontalSpacer(6));
		
		ScrollPanel scrollPanel = new ScrollPanel();
		scrollPanel.setHeight("350px");
		
		tabPanel = new TabPanel();
		add(tabPanel);
		
		vpAddNew = new VerticalPanel();
		tabPanel.add(vpAddNew, "Add New", false);
		vpAddNew.setSize("985px", "");
		
		vpManage = new VerticalPanel();
		tabPanel.add(vpManage, "Manage", false);
		vpManage.setSize("985px", "100px");
		
		GridView gridView = new GridView();
		gridView.setGridData(AdminManager.getGridData());
		gridView.render();
		
		vpManage.add(gridView);
		
		tabPanel.selectTab(0);
		
		hpFooter = new HorizontalPanel();
		hpFooter.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		add(hpFooter);
		hpFooter.setSize("1000px", "");
		
		Label lblCopyright = new Label("Copyright");
		hpFooter.add(lblCopyright);
		vpAddNew.add(new UserForm());
	}
	
	public NavigationBar gerNavBar() {
		
		NavigationBar navigationBar = new NavigationBar();
    		navigationBar.addNavItem("User Manager");
    		navigationBar.addNavItem("Hall Manager");
    		navigationBar.addNavItem("Hall Booking");
    		
    		navigationBar.addAttachHandler(new NavChangeEventHandler() {
				
				@Override
				public void onNavChangeEvent(NavChangeEvent navChangeEvent) {
//					Window.alert("Selected Index : " + navChangeEvent.getSelectedIndex());
					vpAddNew.clear();
					switch (navChangeEvent.getSelectedIndex()) {
					case 0:
						vpAddNew.add(new UserForm());
						break;

					case 1:
						vpAddNew.add(new HallForm());
						break;
						
					default:
						break;
					}
				}
			});
		return navigationBar;
	}
	
}
